import { defineStore } from 'pinia'
import { getUnreadMessageList } from '@/api/message'


interface IUnreadMessageItem {
    id: number
    alertMessageId: number
    alertGrade: string
    alertContent: string | null
    alertTime: string | Date
}

interface IUseMessageStore {
    totalCount: number
    unreadMessageList: Array<IUnreadMessageItem>
}

export const useMessageStore = defineStore('messageStore', {
    state: () => ({
        // 未读消息总数
        totalCount: 0,
        // 未读消息列表
        unreadMessageList: []
    } as IUseMessageStore),
    actions: {
        async getUnreadMessageList() {
            const { data } = await getUnreadMessageList()
            this.totalCount = data.totalCount || 0
            this.unreadMessageList = data.message || []
        }
    }
})